package com.howcan.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

public class FullHitFrameLayout extends FrameLayout
{
  private View target;

  public FullHitFrameLayout(Context paramContext)
  {
    super(paramContext);
  }

  public FullHitFrameLayout(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
  }

  public FullHitFrameLayout(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
  }

  public boolean dispatchTouchEvent(MotionEvent paramMotionEvent)
  {
	boolean bool = false;
    if (getChildCount()> 0) {
        target = getChildAt(0);
    }
    
	switch (paramMotionEvent.getAction()) {
    
	case MotionEvent.ACTION_MOVE :

          if (target != null) {
        	  MotionEvent localMotionEvent2 = MotionEvent.obtain(paramMotionEvent);
        	  float f3 = paramMotionEvent.getX();
        	  float f4 = paramMotionEvent.getY();
        	  if (f3 < this.target.getLeft())
        	  	  f3 = this.target.getLeft();
        		  else if (f4 < this.target.getTop())
        			  f4 = this.target.getTop();
        	  else  if (f3 >= this.target.getRight())
        		  	f3 = -5 + this.target.getRight();
        		  	else if (f4 >= this.target.getBottom())
        		  		f4 = -5 + this.target.getBottom();
        	         	  
            localMotionEvent2.setLocation(f3, f4);
            return super.dispatchTouchEvent(localMotionEvent2);
          }
          break;
        
    case MotionEvent.ACTION_OUTSIDE :
        if ((this.target != null) && (paramMotionEvent.getX() < 0.0F) && (paramMotionEvent.getX() > getWidth()) && (paramMotionEvent.getY() < 0.0F) && (paramMotionEvent.getY() > getHeight())){
        	MotionEvent localMotionEvent1 = MotionEvent.obtain(paramMotionEvent);
        	float f1 = paramMotionEvent.getX();
        	float f2 = paramMotionEvent.getY();
        	if (f1 < this.target.getLeft())
        		f1 = this.target.getLeft();
        		else if (f2 < this.target.getTop())
        			f2 = this.target.getTop();
        		else if (f1 >= this.target.getRight()) {
        			f1 = -5 + this.target.getRight();
        			if (f2 >= this.target.getBottom())
        				f2 = -5 + this.target.getBottom();
        		}
        	localMotionEvent1.setLocation(f1, f2);
        	return super.dispatchTouchEvent(localMotionEvent1);
        }
        break;
    default :
        return super.dispatchTouchEvent(paramMotionEvent);
    }
	return bool;
   }

}